﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TheBullysStore.Controllers;
using TheBullysStore.Models.ModuloAdministracion.TipoDoc;
using System.Data.SqlClient;
using log4net;

namespace TheBullysStore.Models.ModuloAdministracion.TipoDoc
{
    public class TipoDocDAO
    {
        public List<TipoDocBean> ListarTipoDoc(TipoDocBean TipoDoc)
        {
            try
            {
                List<TipoDocBean> listaTipoDoc = new List<TipoDocBean>();

                String cadenaConfiguracion = ConfigurationManager.ConnectionStrings["TheBullysStore"].ConnectionString;

                SqlConnection sqlCon = new SqlConnection(cadenaConfiguracion);

                sqlCon.Open();

                string commandString = "SELECT * FROM tipo_documento WHERE estado = 1"; 

                SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);

                SqlDataReader dataReader = sqlCmd.ExecuteReader();

                while (dataReader.Read()){
                    TipoDocBean tipoDoc = new TipoDocBean();
                    tipoDoc.TipoDocumento = Convert.ToString(dataReader["tipo_documento"]);
                    tipoDoc.Descripcion = Convert.ToString(dataReader["Descripcion"]);
                    tipoDoc.Estado = Convert.ToInt32(dataReader["Estado"]);
                    tipoDoc.Categoria = Convert.ToString(dataReader["categoria"]);
                    listaTipoDoc.Add(tipoDoc);                   
                }
                dataReader.Close();
                sqlCon.Close();

                return listaTipoDoc;
            }
            catch (Exception e)
            {
                String men = e.ToString();
                TipoDoc.Conexion = men;
                return null;
            }
        }
    }
}